//
//  VGIMOCSessionConfigurator.m
//  IMTest
//
//  Created by 宋海胜 on 2019/4/22.
//  Copyright © 2019年 宋海胜. All rights reserved.
//

#import "VGIMOCSessionConfigurator.h"
#import "NIMSessionMsgDatasource.h"
#import "NIMSessionInteractorImpl.h"
#import "NIMCustomLeftBarView.h"
#import "UIView+NIM.h"
#import "NIMMessageModel.h"
#import "NIMGlobalMacro.h"
#import "NIMSessionDataSourceImpl.h"
#import "NIMSessionLayoutImpl.h"
//#import "NIMSessionTableAdapter.h"
#import "VGIMOCSessionTableAdapter.h"
#import "VGIMOCSessionLayoutImpl.h"
/*
 NIMSessionViewController 类关系图
 
 
 .........................................................................
 .                                                                       .
 .                                                                       .
 .                                                                       .                  | ---> [NIMSessionDatasource]
 .                                                                       .
 .                                                       | ---> [NIMSessionInteractor] -->  |
 .
 .                                                                                          | ---> [NIMSessionLayout]
 .
 ↓
 [NIMSessionViewController]-------> [NIMSessionConfigurator] -----> |
 |
 |
 |
 |
 ↓                                                       | ---> [NIMSessionTableAdapter]
 [UITableView]                                                              .
 ↑                                                                     .
 .                                                                     .
 .                                                                     .
 .......................................................................
 */

@interface VGIMOCSessionConfigurator()

@property (nonatomic,strong) NIMSessionInteractorImpl   *interactor;

@property (nonatomic,strong) VGIMOCSessionTableAdapter     *tableAdapter;

@end

@implementation VGIMOCSessionConfigurator

- (void)setup:(VGIMOCSessionViewController *)vc
{
    NIMSession *session    = vc.session;
    id<NIMSessionConfig> sessionConfig = vc.sessionConfig;
    UITableView *tableView  = vc.tableView;
    VGIMOCInputView *inputView = vc.sessionInputView;
    
    NIMSessionDataSourceImpl *datasource = [[NIMSessionDataSourceImpl alloc] initWithSession:session config:sessionConfig];
    VGIMOCSessionLayoutImpl *layout         = [[VGIMOCSessionLayoutImpl alloc] initWithSession:session config:sessionConfig];
    layout.tableView = tableView;
    layout.inputView = inputView;
    
    
    _interactor                          = [[NIMSessionInteractorImpl alloc] initWithSession:session config:sessionConfig];
    _interactor.delegate                 = vc;
    _interactor.dataSource               = datasource;
    _interactor.layout                   = layout;
    
    [layout setDelegate:_interactor];
    
    _tableAdapter = [[VGIMOCSessionTableAdapter alloc] init];
    _tableAdapter.interactor = _interactor;
    _tableAdapter.delegate   = vc;
    vc.tableView.delegate = _tableAdapter;
    vc.tableView.dataSource = _tableAdapter;
    
    
    [vc setInteractor:_interactor];
}


@end
